Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple: Fix AF_SYSTEM and AF_SYS_CONTROL #3047

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

siegfried
Copy link
Contributor

@siegfried siegfried commented Dec 23, 2022

Trying to fix the issue #3044

Here is the definition I found:

/*!
 *       @struct sockaddr_ctl
 *       @discussion The controller address structure is used to establish
 *               contact between a user client and a kernel controller. The
 *               sc_id/sc_unit uniquely identify each controller. sc_id is a
 *               unique identifier assigned to the controller. The identifier can
 *               be assigned by the system at registration time or be a 32-bit
 *               creator code obtained from Apple Computer. sc_unit is a unit
 *               number for this sc_id, and is privately used by the kernel
 *               controller to identify several instances of the controller.
 *       @field sc_len The length of the structure.
 *       @field sc_family AF_SYSTEM.
 *       @field ss_sysaddr AF_SYS_KERNCONTROL.
 *       @field sc_id Controller unique identifier.
 *       @field sc_unit Kernel controller private unit number.
 *       @field sc_reserved Reserved, must be set to zero.
 */
struct sockaddr_ctl {
	u_char      sc_len;     /* depends on size of bundle ID string */
	u_char      sc_family;  /* AF_SYSTEM */
	u_int16_t   ss_sysaddr; /* AF_SYS_KERNCONTROL */
	u_int32_t   sc_id;      /* Controller unique identifier  */
	u_int32_t   sc_unit;    /* Developer private unit number */
	u_int32_t   sc_reserved[5];
};

Shall I alias AF_SYS_CONTROL to AF_SYS_KERNCONTROL?

@rustbot
Copy link
Collaborator

rustbot commented Dec 23, 2022

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @JohnTitor (or someone else) soon.

Please see the contribution instructions for more information.

@@ -3606,7 +3606,7 @@ pub const PF_ISDN: ::c_int = AF_ISDN;
pub const PF_KEY: ::c_int = pseudo_AF_KEY;
pub const PF_INET6: ::c_int = AF_INET6;
pub const PF_NATM: ::c_int = AF_NATM;
pub const PF_SYSTEM: ::c_int = AF_SYSTEM;
pub const PF_SYSTEM: ::c_int = 32;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the type of PF_SYSTEM to c_int regarding the man page of SOCKET(2):

NAME
     socket – create an endpoint for communication

SYNOPSIS
     #include <sys/socket.h>

     int
     socket(int domain, int type, int protocol);

DESCRIPTION
     socket() creates an endpoint for communication and returns a descriptor.

     The domain parameter specifies a communications domain within which communication will take place; this selects the protocol family which should be used.  These
     families are defined in the include file ⟨sys/socket.h⟩.  The currently understood formats are

           PF_LOCAL        Host-internal protocols, formerly called PF_UNIX,
           PF_UNIX         Host-internal protocols, deprecated, use PF_LOCAL,
           PF_INET         Internet version 4 protocols,
           PF_ROUTE        Internal Routing protocol,
           PF_KEY          Internal key-management function,
           PF_INET6        Internet version 6 protocols,
           PF_SYSTEM       System domain,
           PF_NDRV         Raw access to network device,
           PF_VSOCK        VM Sockets protocols

     The socket has the indicated type, which specifies the semantics of communication.  Currently defined types are:

           SOCK_STREAM
           SOCK_DGRAM
           SOCK_RAW

     A SOCK_STREAM type provides sequenced, reliable, two-way connection based byte streams.  An out-of-band data transmission mechanism may be supported.  A SOCK_DGRAM
     socket supports datagrams (connectionless, unreliable messages of a fixed (typically small) maximum length).  SOCK_RAW sockets provide access to internal network
     protocols and interfaces.  The type SOCK_RAW, which is available only to the super-user.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just change to AF_SYSTEM as c_int rather than duplicating the literal

pub const AF_NETBIOS: ::c_int = 33;
pub const AF_PPP: ::c_int = 34;
pub const pseudo_AF_HDRCMPLT: ::c_int = 35;
pub const AF_SYS_CONTROL: ::c_int = 2;
pub const AF_SYS_CONTROL: ::c_ushort = 2;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old examples uses the value of AF_SYS_CONTROL for AF_SYS_KERNCONTROL. I can also add AF_SYS_KERNCONTROL and leave AF_SYS_CONTROL untouched.

@siegfried
Copy link
Contributor Author

Is there anything else needed from me?

@JohnTitor
Copy link
Member

Changing types is a breaking change and we don't ship it on minor releases. I'll revisit once we decide to do a major release.

@tgross35
Copy link
Contributor

tgross35 commented Nov 20, 2024

We have an upcoming major release where we can do breaking changes.

It seems unusual to only change one AF_* type - should they all be changed?

@tgross35
Copy link
Contributor

@rustbot author for the above question

@siegfried
Copy link
Contributor Author

Updated. Sorry for the delay. Please review.

@tgross35 tgross35 changed the title Fix AF_SYSTEM and AF_SYS_CONTROL Apple: Fix AF_SYSTEM and AF_SYS_CONTROL Feb 23, 2025
@tgross35
Copy link
Contributor

tgross35 commented Feb 23, 2025

Just to clarify; is sc_family only ever set to AF_SYSTEM and ss_sysaddr is only ever AF_SYS_CONTROL? Meaning no other constants are ever used for these fields.

pub const AF_NETBIOS: c_int = 33;
pub const AF_PPP: c_int = 34;
pub const pseudo_AF_HDRCMPLT: c_int = 35;
pub const AF_IEEE80211: c_int = 37;
pub const AF_UTUN: c_int = 38;
pub const AF_VSOCK: c_int = 40;
pub const AF_SYS_CONTROL: c_int = 2;
pub const AF_SYS_CONTROL: c_ushort = 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub const AF_SYS_CONTROL: c_ushort = 2;
pub const AF_SYS_CONTROL: c_ushort = 2;

It looks like the field is u_int16_t, so this can just be u16 https://developer.apple.com/documentation/kernel/sockaddr_ctl/1809252-ss_sysaddr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Waiting on CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI test failed after I change AF_SYS_CONTROL to u16. Any idea why? @tgross35

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look related, the android CI has been flaky.

@siegfried
Copy link
Contributor Author

Just to clarify; is sc_family only ever set to AF_SYSTEM and ss_sysaddr is only ever AF_SYS_CONTROL? Meaning no other constants are ever used for these fields.

I think so regarding to the document.

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please squash. I think the CI failure is unrelated.

Since this is breaking:

@rustbot label +stable-declined

@rustbot rustbot added the stable-declined This change is breaking, difficult to backport, low priority, or otherwise not relevant for 0.2 label Feb 23, 2025
@siegfried
Copy link
Contributor Author

Squashed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breakage-candidate O-macos O-unix S-waiting-on-author stable-declined This change is breaking, difficult to backport, low priority, or otherwise not relevant for 0.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants